package com.itheima.example;

/**
     需求：使用方法完成统计1-n的数据和并返回。
 */
public class Test1 {
    public static void main(String[] args) {
        int rs = sum(10);
        System.out.println("1-10的和是：" + rs);

        System.out.println("-----------------");

        int rs1 = sum(100);
        System.out.println("1-100的和是：" + rs1);
    }

    public static int sum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }
}
